//操作选项
var operateGrid;
var operateWin;
Ext.onReady(function(){
	var operateStore = Ext.create('Ext.data.JsonStore', {
	    //storeId:'simpsonsStore',
		autoLoad:true,
		fields:["operateId", "operateName","remarks"],
		proxy: {
		    type: 'ajax',
		    url: opts.operate_url+'&workFlowId='+flowId,
		    reader: {
		        type: 'json',
		        root: 'operates',
		        idProperty: 'name'
		    }
		}
	});
	
	operateGrid = Ext.create('Ext.grid.Panel', {
	    store: operateStore,
	    multiSelect: true, 
	   // autoScroll: true,
	   // height:245,
	    selModel: {  
            selType:'checkboxmodel'  
        }, 
	    columns: [
	    	Ext.create('Ext.grid.RowNumberer', {text: '序号', width : 30}),
	      	{ dataIndex:"operateId",hidden:true},	 	
	    	{ header:"操作名称",dataIndex:"operateName",width: 200},
	    	{ header:"备注",dataIndex:"remarks",width: 200}
	    ]
	});

	operateWin = Ext.create('Ext.Window',{
		title: '事件选择器',
		modal: true,
		width: 400,
		height:400,
		autoScroll: true,
		buttonAlign : 'center',
		closeAction: 'hide',
		items:operateGrid,
		listeners:{
			'close':function(){
				Ext.get(Ext.DomQuery.select(".key_btn_down")).removeCls("key_btn_down"); 
			}
		},
		buttons: [{
			text: '确定',
			handler: function(){
				 saveOperates();
				 operateWin.close();
			}
		},{
			text: '关闭',
	        	handler: function(){
	        		operateWin.close();
	        	}
	        }
		]
	});
	
});

function saveOperates(){
	
	var record = operateGrid.getSelectionModel().getSelection();
	var operate = '';
	Ext.each(record, function(res){
        operate += res.get("operateId") + '-' + res.get("operateName") + ',';
	});
	modifyXmlNodeAttribute(opts.curXmlNode, "operate", operate.substring(0,operate.length-1));
	
}

function setOperates(){
	if(opts.curXmlNode != null){
		operateWin.show();	
		operateGrid.getSelectionModel().deselectAll();//取消checkbox选中
		
		var operate = opts.curXmlNode.getAttribute("operate");
		if(operate != null){
			var ops = operate.split(",");
			operateGrid.getStore().each(function(res){
	
				for(var i = 0;i < ops.length; i++ ){
					var _obj = ops[i].split("-");
					if(res.get('operateId')==_obj[0]){
						operateGrid.getSelectionModel().select(res, true);
					} 
				}
			});
		}
	}
	
}
